<?php
Class C_users extends Cemvc_Control_Base
{
  /* public function __empty() */
  /* { */
  /*   $Mdb=M_Qin_Users::getInstance(); */
  /*   $arr=$Mdb->getByUsername(preg_replace("/\.html$/i","",MethodAction)); */
  /*   $this->assign("student",$arr);	 */
  /*   $this->display('student/info.html'); */
  /* } */
  public function insert()
  {
    session_start();
    if($_POST)
      {
	if($_POST['vc']==$_SESSION['CaptchaCode'])
	  {	
	    $Mdb=M_Qin_Users::getInstance();
	    $data["qq_open_id"]=$_POST['qq_open_id'];
	    $data["realname"]=$_POST['realname'];
	    $data["gender"]=$_POST['gender'];
	    $data["region_code"]=$_POST['region_code'];
	    $data["day_of_birth"]=$_POST['day_of_birth'];
	    $data["figureurl"]=$_POST['figureurl'] ? $_POST['figureurl'] : "";
	    $data["creator"]=$_POST['creator'];
	    $Mdb->insert($data);							
	  }
	else
	  {
	    $this->assign("alert","验证码错误");
	  }
		
      }
    $this->display();
  }
  public function update()
  {

    //$Mdb->SetDbCodeNames("utf8");
    if(!$_GET['id'])
      {
	//echo 'test';
	/* $this->update_list();	 */
	$this->assign("error", "没有指定用户id。");	
      }
    else
      {
	$Mdb=M_Qin_Users::getInstance();
	if($_POST)
	  {
	    /* $Mdb->where(array("id=$_GET[id]"))->update($_POST);//必须将按钮名设为空 */
	    /* 更安全的方法 */
	    $data["realname"]=$_POST['realname'];
	    $data["gender"]=$_POST['gender'];
	    $data["region_code"]=$_POST['region_code'];
	    $data["day_of_birth"]=$_POST['day_of_birth'];
	    $data["figureurl"]=$_POST['figureurl'] ? $_POST['figureurl'] : "";
	    $Mdb->where(array("id=$_GET['id']"))->update($data);	
	  }

	/* $this->assign("student",$Mdb->find($_GET['id'])); */	
      }
    $this->display();

  }
  /* public function update_list() */
  /* { */
  /*   $Mdb=M_Qin_Users::getInstance(); */
  /*   $arr=$Mdb->where(array("id>14"))->limit(3)->fetchAll();//每页三行 */
  /*   $this->assign("students",$arr);	 */
  /*   $this->assign("page_str",$Mdb->showPages("/student/update/page/",6));//显示区间为6，/demo/show/page/ */
  /*   $this->display("student/update_list.html"); */
  /* }	 */
  public function delete()
  {
    if(!$_GET['id'])
      {
	$this->delete_list();	
      }
    else
      {
	$Mdb=M_Qin_Users::getInstance();

	$Mdb->where(array("id=$_GET[id]"))->delete();
	/* $this->delete_list(); */	
      }

  }
  /* public function delete_list() */
  /* { */
  /*   $Mdb=M_Qin_Users::getInstance(); */
  /*   $arr=$Mdb->where(array("id>14"))->limit(3)->fetchAll();//每页三行 */
  /*   $this->assign("students",$arr);	 */
  /*   $this->assign("page_str",$Mdb->showPages("/student/delete/page/",6));//显示区间为6，/demo/show/page/ */
  /*   $this->display("student/delete_list.html"); */
  /* } */
  public function info()
  {
    $Mdb=M_Qin_Users::getInstance();
    if($_GET['name'])
      $arr=$Mdb->getByUsername($_GET['name']);
    else
      $arr=$Mdb->find($_GET['id']);
    $this->assign("user",$arr);	

    $this->display();
  }
}
//utf8编码
?>